package com.fbs.service.impl;

import com.fbs.dao.UserDao;
import com.fbs.entity.User;

import com.fbs.service.UserService02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;



@Service
public class UserServiceImpl02 implements UserService02 {
    @Autowired
    private UserDao userDao;

    @Override
    @Cacheable(cacheNames = "redis::user",key = "#id")
    public User findById(Integer id) {

        User user = userDao.selectById(id);
        return user;
    }

    @Override
    @CacheEvict(cacheNames = "redis::user",key = "#id")
    public Integer delById(Integer id) {
        int i = userDao.deleteById(id);
        return i;
    }

    @Override
    public User save(User user) {
        userDao.insert(user);
        return user;
    }

    @Override
    @CachePut(cacheNames = "redis::user",key = "#user.id")
    public User update(User user) {

        userDao.updateById(user);
        return user;

    }
}
